﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;

namespace SmashedApples.Core
{
    public class ValueObject : Hashtable
    {
    
        public ValueObject() { }
        public ValueObject(DataTable table)
        {
            this.set(table);
        }
        public ValueObject(DataRow row)
        {
            this.set(row);
        }
        public ValueObject(Hashtable args)
        {
            this.set(args);
        }
        public ValueObject(Hashtable args, ValueObject vo)
        {
            this.merge(args, vo);
        }
        public void set(DataRow row)
        {
            foreach (DataColumn column in row.Table.Columns)
            {
                this[column.ColumnName] = row[column];
            }
        }
        public void set(DataTable table)
        {
            if (table.Rows.Count != 0)
            {
                this.set(table.Rows[0]);
            }
        }
        public void set(Hashtable hashtable)
        {
            foreach (DictionaryEntry entry in hashtable)
            {
                this[entry.Key] = hashtable[entry.Key];
            }

        }
        public void merge(Hashtable hashtable, ValueObject vo)
        {

            foreach (String key in vo.Keys)
            {
                if (hashtable.Contains(key))
                {
                    this[key] = hashtable[key];
                }
                else
                {
                    this[key] = vo[key];
                }
            }
        }





    }
}
